'''
@Author: Lin Qi Ping
@Date: 2019-12-30 16:40:00
@LastEditors  : Lin Qi Ping
@LastEditTime : 2020-01-03 15:57:24
@Description: 
'''
import pymysql
class MysqlHelp(object):
    def __init__(self):
        self.conn=pymysql.connect(host='127.0.0.1',user='root',password='123456789',port=3306,db='phone_belong_region',charset='utf8')
        self.cursor=self.conn.cursor()
    
    def execute_sql(self,sql,data='',mode='w'):
        if mode=='w':
            self.cursor.executemany(sql,data)
            data=self.conn.insert_id()
            self.conn.commit()
        else:
            self.cursor.execute(sql,data)
            data=self.cursor.fetchall()
        return data
        
    def __del__(self):
        self.cursor.close()
        self.conn.close()
if __name__ == "__main__":
    my=MysqlHelp()
    # sql='insert into db_housesecond_sh(about_id,about_url,title,model1,model2,model3,area,total,unit,direction,layer,total_layer,isdecorate,decorate,`desc`,xq,wz,`status`,create_time,imgs,owner_name,owner_phone,sf,yg,zyqs,`type`,ncq,nj) values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)'
    sql='select * from db_housesecond_sh where title="天光单间低价出售"'
    print(my.execute_sql(sql,mode='r'))
    

